<cfparam name="dir" default="/">
<cfoutput>
  <script type="text/javascript" src="#request.absoluteadminpath#js/tinymce/tiny_mce_popup.js"></script>
</cfoutput>
<script>tinyMCEPopup.onInit.add(FileBrowserDialogue.init, FileBrowserDialogue);</script>
<style>
body {
	background: #FFFFFF;
}
</style>
<!---if image is uploaded them select uploaded image and close--->
<cfif isdefined('url.linkfilename')>
  <cfset linkurl = "#dir##linkfilename#">
  <cfoutput>
    <script>
    FileBrowserDialogue.getlink('#linkurl#');
	</script>
  </cfoutput>
</cfif>
<script language="javascript">
function fmcopyfiles () {
	resetbox(); 
	$('#dialog').load('dialogs/filemanager/selectfolder_copy.cfm').dialog({modal: true,my: 'center',at: 'center',of: window,width: 400,height: 300,title:'Copy To'});
}

function fmmovefiles() {
	resetbox(); 
	$('#dialog').load('dialogs/filemanager/selectfolder_move.cfm').dialog({modal: true,my: 'center',at: 'center',of: window,width: 400,height: 300,title:'Move To'});
}

function fmshowrename() {
	resetbox(); 
	$('#dialog').load('dialogs/filemanager/renamefile.cfm').dialog({modal: true,my: 'center',at: 'center',of: window,width: 400,height: 300,title:'Copy To'});
}

function fmdocopy(folderpath) {
	document.getElementById('tofolder').value = '/' + folderpath;
	document.getElementById('the_action').value = 'docopy';
	document.forms["filemanager"].submit();
}

function fmdomove(folderpath) {
	document.getElementById('tofolder').value = '/' + folderpath;
	document.getElementById('the_action').value = 'domove';
	document.forms["filemanager"].submit();
}

</script>
<cfparam name = "dir" default="/">
<cfparam name = "showfolders" default="0">
<cfif isdefined('cookie.folders')>
  <cfif cookie.folders IS 1>
    <cfset showfolders = 1>
  </cfif>
  <cfif cookie.folders IS 0>
    <cfset showfolders = 0>
  </cfif>
</cfif>
<cfif dir IS '/'>
  <cfset has_access = 'Yes'>
  <cfelse>
  <cfset has_access = 'No'>
  <cfloop from = "1" to = "#listlen(request.folder_accesslist)#" index="f">
    <cfset folder_name = listgetat(request.folder_accesslist, f)>
    <cfif #listgetat(dir, 1, "/")# IS #folder_name#>
      <cfset has_access = 'Yes'>
    </cfif>
  </cfloop>
</cfif>
<cfif has_access IS 'No'>
  <cfset dir = '/'>
</cfif>
<cfset fullpath = "#request.adminpath##dir#">
<cfset fullpath = replacenocase(FullPath, "//", "/", "ALL")>
<cfset dir = replacenocase(dir, "//", "/", "ALL")>
<cfinvoke component="cfcs.admin.filemanager" method="getfiles" fullpath="#fullpath#" returnvariable="qfiles" />
<cfinvoke component="cfcs.admin.filemanager" method="getfolders" fullpath="#fullpath#" returnvariable="qfolders" />
<div id="component_menus">
  <cfif NOT dir IS '/' AND NOT listlen(dir, "/") GT 3>
    <cfset upload_disabled = 0>
    <cfelse>
    <cfset upload_disabled = 1>
  </cfif>
  <cfinvoke component="cfcs.common.buttons" method="show" width="125" btext="Upload a File" tooltip="Upload a file and link to it" jscript="simpleexpandcollapse('fileupload');" img="upload.png" isdisabled="#upload_disabled#" />
  <div class="clear"></div>
</div>
<div style="display: none; border: 1px solid #003366; padding: 20px;" id="fileupload"> <cfoutput>
    <script type="text/javascript">
$(document).ready(function() {
  $('##file_upload').uploadify({
	'uploader'  : '#request.absoluteadminpath#js/uploadify/uploadify.swf',
	'script'    : '#request.absoluteadminpath#upload/upload.cfm',
	'cancelImg' : '#request.absoluteadminpath#images/defaults/cancel.png',
	'folder'    : '#dir#',
	'scriptData'  :{'filepath':'#request.adminpath#','dir':'#dir#'},	
	'auto'      : true,
	'multi'		: false,
	'buttonText': 'Select File',	
	'queueSizeLimit' : 20,
	'sizeLimit' : 183500800,
	'onComplete' : function(event, queueID, fileObj, response, data) {
	var relocateto = 'browse.cfm?win=#win#&type=file&dir=#dir#&linkfilename='+fileObj.name;
	window.location.href = relocateto;
	}	
  });
});
</script>
  </cfoutput>
  <input id="file_upload" name="file_upload" type="file" />
</div>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
  <!---If this is the main folder then display the default folders--->
  <cfoutput>
    <tr>
      <td id="columnheaders" colspan="4" style="cursor: pointer;" onclick="expandcollapse('folders','expandcollapseimg','#request.absoluteadminpath#images/defaults/');">Folders [Current Path: <cfoutput>#dir#</cfoutput>]</td>
      <td id="columnheaders" align="right" style="cursor: pointer;" onclick="expandcollapse('folders','expandcollapseimg','#request.absoluteadminpath#images/defaults/');"><cfif NOT dir IS '/'> <img src="#request.absoluteadminpath#images/defaults/collapse.gif" border="0" id="expandcollapseimg" />
        </cfif></td>
    </tr>
  </cfoutput>
  <cfif dir IS '/'>
    <cfset ImageName = 'folder.png'>
    <cfloop from = "1" to = "#listlen(request.folder_accesslist)#" index="f">
      <cfset folder_name = listgetat(request.folder_accesslist, f)>
      <cfoutput>
        <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';">
          <td colspan="4" class="menu_cell" onclick="window.location.href = 'browse.cfm?win=#win#&type=file&showfolders=1&dir=#dir##folder_name#/';"><img src="#request.absoluteadminpath#images/#ImageName#" align="absmiddle"> <a href = "browse.cfm?win=#win#&type=file&showfolders=1&dir=#dir##folder_name#/">#folder_name#</a></td>
          <td class="menu_cell"></td>
        </tr>
      </cfoutput>
    </cfloop>
  </cfif>
  <!---If it's not the main folder then display the list of folders in this directory--->
  <cfif NOT dir IS '/'>
    <!---figure out which directory is up one from this one--->
    <cfset PathLength = listlen(dir, "/")>
    <cfset UpdirName = ListDeleteAt(dir, PathLength, '/')>
    <cfif UpdirName IS ''>
      <cfset UpdirName = '/'>
    </cfif>
    <cfif NOT right(UpdirName, 1) IS '/'>
      <cfset updirName = "#updirName#/">
    </cfif>
    <cfoutput>
      <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';" onClick="browse.cfm?win=#win#&type=file&dir=#UpdirName#">
        <td colspan="5" class="menu_cell"><img src="#request.absoluteadminpath#images/folder_up.png" align="absmiddle" width="24"> <cfoutput><a href = "browse.cfm?win=#win#&type=file&dir=#UpdirName#">[Parent Folder]</a></cfoutput> </td>
      </tr>
    </cfoutput>
    <tr>
    
    <td colspan="5">
    
    <div id="folders" <cfif showfolders IS 0>style="display: none;"</cfif>>
      <table width="100%" cellpadding="4" cellspacing="0">
        <cfoutput Query = "qfolders">
          <cfset ImageName = 'folder.png'>
          <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';">
            <td width="90%" class="menu_cell" onclick="window.location.href = 'browse.cfm?win=#win#&type=file&dir=#dir##Name#/';"><img src="#request.absoluteadminpath#images/#ImageName#" align="absmiddle"> <a href = "browse.cfm?win=#win#&type=file&dir=#dir##Name#/">#Name#</a></td>
            <td width="10%" class="menu_cell"><div align="right"></div></td>
          </tr>
        </cfoutput>
      </table>
    </div>
    <cfif NOT dir IS '/' AND qfolders.recordcount GT 0>
      <cfoutput>
        <cfif showfolders IS 0>
          <div id="expandcollapse_msg" style="display: block;" onclick="expandcollapse('folders','expandcollapseimg','#request.absoluteadminpath#images/defaults/');">Click to Expand</div>
        </cfif>
      </cfoutput>
    </cfif>
  </cfif>
  <cfif NOT dir IS '/' AND qfolders.recordcount IS 0>
    <tr>
      <td colspan="5"><div id="messages_info">No folders found in current path.</div></td>
    </tr>
  </cfif>
  <cfif NOT dir IS '/'>
    <tr>
      <td id="columnheaders"></td>
      <td id="columnheaders">File Name</td>
      <td id="columnheaders">Size</td>
      <td id="columnheaders">Date Last Modified</td>
      <td id="columnheaders">&nbsp;</td>
    </tr>
    <!---if it's not the main folder then list the files--->
    <form name = "filemanager" id="filemanager" action="browse.cfm?win=#win#&type=file&dir=#dir#" method="Post">
    
    <cfif NOT dir IS '/'>
      <cfoutput query = "qfiles">
        <!---Figure out what action to use on this file from it's file type--->
        <cfset theaction = 'download'>
        <cfset theicon='document.png'>
        <cfset thetype='none'>
        <cfif Right(name, 4) IS '.gif' OR right(name, 4) IS '.jpg' OR right(name, 4) IS '.png' OR right(name, 4) IS 'jpeg'>
          <cfset theicon='image.png'>
          <cfset thetype='Image'>
        </cfif>
        <cfif Right(name, 4) IS '.cfm' OR right(name, 5) IS '.html' OR right(name, 4) IS '.txt' OR right(name, 4) IS '.asp' OR right(name, 4) IS '.cfm' OR right(name, 4) IS '.php' OR right(name, 4) IS '.htm'>
          <cfset theicon='document_html.png'>
          <cfset thetype='webpage'>
        </cfif>
        <cfif Right(name, 4) IS '.pdf'>
          <cfset theicon='document_pdf.png'>
          <cfset thetype='pdf'>
        </cfif>
        <cfif Right(name, 4) IS '.doc' OR Right(name, 5) IS '.docx'>
          <cfset theicon='document_word.png'>
          <cfset thetype='word'>
        </cfif>
        <cfif Right(name, 4) IS '.xls' OR Right(name, 5) IS '.xlsx'>
          <cfset theicon='document_excel.png'>
          <cfset thetype='excel'>
        </cfif>
        <cfif Right(name, 4) IS '.avi' OR right(name, 4) IS 'mov' OR right(name, 4) IS '.mpg' OR right(name, 4) IS '.wmv' OR right(name, 4) IS '.mp4'>
          <cfset theicon='movie.png'>
          <cfset thetype='video'>
        </cfif>
        <cfif Right(name, 4) IS '.swf' OR Right(name, 4) IS '.flv'>
          <cfset theicon='document_flash.png'>
          <cfset thetype='flash'>
        </cfif>
        <cfif Right(name, 4) IS '.csv' OR Right(name, 4) IS '.txt'>
          <cfset theicon='document.png'>
          <cfset thetype='datafile'>
        </cfif>
        <cfif Right(name, 4) IS '.css'>
          <cfset theicon='document_css.png'>
          <cfset thetype='datafile'>
        </cfif>
        <cfif Right(name, 3) IS '.js'>
          <cfset theicon='document_javascript.png'>
          <cfset thetype='datafile'>
        </cfif>
        <cfif Right(name, 4) IS '.csv' OR Right(name, 4) IS '.txt'>
          <cfset theicon='document.png'>
          <cfset thetype='datafile'>
        </cfif>
        <cfif Right(name, 4) IS '.mp3' OR Right(name, 4) IS '.rm' OR Right(name, 4) IS '.ram' OR Right(name, 4) IS '.aif' OR Right(name, 4) IS '.aiff' OR Right(name, 4) IS '.wav' OR Right(name, 4) IS '.wma'>
          <cfset theicon='document_audio.png'>
          <cfset thetype='datafile'>
        </cfif>
        <cfif Right(name, 4) IS '.zip'>
          <cfset theicon='document_zip.png'>
          <cfset thetype='compressedfile'>
        </cfif>
        <cfif Right(name, 4) IS '.rar'>
          <cfset theicon='document_rar.png'>
          <cfset thetype='compressedfile'>
        </cfif>
        <!---Display the list of files and the appropriate icon next to it--->
        <cfset idname = replace(name, ".", "", "ALL")>
        <cfset idname = replace(idname, " ", "", "ALL")>
        <tr class="menu_row" onMouseOver="this.className = 'menu_row_over2';" onMouseOut="this.className = 'menu_row';" onClick="FileBrowserDialogue.getlink('#dir##name#');">
          <td valign="middle" class="menu_cell" width="5%"><img src="#request.absoluteadminpath#images/filetypes/#theicon#" align="absmiddle"> </td>
          <td valign="middle" class="menu_cell"><span id = "norename_#idName#" style="display: block;"> #Name#</span> </td>
          <td width="50" class="menu_cell" valign="middle"><div align="left">
              <cfif Size LT 1000>
                <cfset mySize = #size#>
                #mySize# b
              </cfif>
              <cfif Size GT 999 AND Size LT 1000000>
                <cfset mySize = #Size# / 1000>
                #Round(mySize)# kb
              </cfif>
              <cfif Size GT 999999>
                <cfset mySize = #Size# / 1000000>
                #Round(MySize)# mb
              </cfif>
            </div></td>
          <td width="200" class="menu_cell">#dateformat(dateLastModified, "mm/dd/yyyy")# #timeformat(dateLastModified, "hh:mm tt")#</td>
          <td width="200" align="right" valign="middle" class="menu_cell"><div align="right"></div></td>
        </tr>
      </cfoutput> <cfoutput>
        <input type = "hidden" value="#dir#" name="dir" id="dir">
        <input type = "hidden" value="" name="name" id="name">
        <input type = "hidden" value="" name="renameto" id="renameto" />
        <input type = "hidden" value="/" name="tofolder" id="tofolder">
        <input type = "hidden" value="RemoveFiles" name="a" id="the_action">
      </cfoutput>
      </form>
      
      <cfif qfiles.recordcount IS 0>
        <tr>
          <td colspan="4"><div id="messages_info">No files exist in the current folder.</div></td>
        </tr>
      </cfif>
    </cfif>
  </cfif>
  <cfif dir IS '/'>
    <tr>
      <td colspan="4"><div id="messages_info">This is the top level folder of your website.  You can not place any files here.  Select a folder above to browse and edit files.</div></td>
    </tr>
  </cfif>
</table>
